package com.crm.service.impl.cluePoolManager;

import com.crm.common.model.Enum.StatusCodeEnum;
import com.crm.dao.mapper.cluePoolManager.ClueVisitRecordMapper;
import com.crm.dao.mapper.customMapper.cluePoolManagerCustomMapper.ClueVisitRecordCustomMapper;
import com.crm.model.entity.cluePoolManager.ClueFollow;
import com.crm.model.entity.cluePoolManager.ClueFollowExample;
import com.crm.model.entity.cluePoolManager.ClueVisitRecord;
import com.crm.model.entity.cluePoolManager.ClueVisitRecordExample;
import com.crm.model.vo.cluePoolManager.ClueVisitRecordVO;
import com.crm.service.cluePoolManager.ClueVisitRecordDbService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ Author ：wll
 */
@Service
public class ClueVisitRecordDbServiceImpl implements ClueVisitRecordDbService {

    @Autowired
    private ClueVisitRecordCustomMapper clueVisitRecordCustomMapper;

    @Autowired
    private ClueVisitRecordMapper clueVisitRecordMapper;

    /**
     * @author wll
     * info 拜访记录
     */
    @Override
    public List<ClueVisitRecordVO> selectClueVisitRecordVOList(String clueId) {
        List<ClueVisitRecordVO> clueVisitRecordVOList = clueVisitRecordCustomMapper.selectClueVisitRecordVOList(clueId);
        return clueVisitRecordVOList;
    }

    /**
     * 新增拜访记录
     * @param clueVisitRecord
     * @return
     */
    @Override
    public Boolean addClueVisitRecord(ClueVisitRecord clueVisitRecord) {
        Boolean result = false;
        int num = clueVisitRecordMapper.insertSelective(clueVisitRecord);
        if (num > 0) {
            result = true;
        }
        return result;
    }

    /**
     * @author wll
     * info 拜访记录
     */
    @Override
    public List<ClueVisitRecord> selectClueVisitRecordList(String clueId) {
        ClueVisitRecordExample clueVisitRecordExample = new ClueVisitRecordExample();
        ClueVisitRecordExample.Criteria criteria = clueVisitRecordExample.createCriteria();
        criteria.andClueIdEqualTo(clueId);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<ClueVisitRecord> list = clueVisitRecordMapper.selectByExample(clueVisitRecordExample);
        return list;
    }

    /**
     * 修改拜访记录
     * @param clueVisitRecord
     * @return
     */
    @Override
    public Boolean updateClueVisitRecord(ClueVisitRecord clueVisitRecord) {
        return clueVisitRecordMapper.updateByPrimaryKeySelective(clueVisitRecord)> 0;
    }

    /**
     * 客户详情拜访记录
     * @param order
     * @param customerId
     * @return
     */
    @Override
    public List<ClueVisitRecord> visitRecordList(String order, String customerId) {
        ClueVisitRecordExample clueVisitRecordExample = new ClueVisitRecordExample();
        clueVisitRecordExample.setOrderByClause(order);
        ClueVisitRecordExample.Criteria criteria = clueVisitRecordExample.createCriteria();
        criteria.andCustomerIdEqualTo(customerId);
        criteria.andDeleteStatusEqualTo(Short.parseShort(String.valueOf(StatusCodeEnum.NORMAL_CODE.getState())));
        List<ClueVisitRecord> list = clueVisitRecordMapper.selectByExample(clueVisitRecordExample);
        return list;
    }

    /**
     * @author wll
     * info 添加拜访 陪访记录
     */
    @Override
    public int insertClueVisitVecord(ClueVisitRecord clueVisitRecord) {
        return clueVisitRecordCustomMapper.insertClueVisitVecord(clueVisitRecord);
    }

    /**
     * 单品客户拜访记录
     * @Author pym
     * @Date  2021/5/12 16:50
     * @param singleProductCustomerId 单品客户ID
     * @param order 排序
     * @param accountId 账号ID
     * @return {@link {java.util.List<com.crm.model.vo.cluePoolManager.ClueVisitRecordVO>}}
     */
    @Override
    public List<ClueVisitRecordVO> selectSingleProductCustomerClueVisitRecordList(String singleProductCustomerId, String order, String accountId) {
        return clueVisitRecordCustomMapper.selectSingleProductCustomerClueVisitRecordList(singleProductCustomerId,order,accountId);
    }
}
